<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;

class ReplayController extends Controller
{
    //
    public function index(Request $request)
    {	
    	$data = DB::table('stroereplay')->where('replayCid',$request->input('commentId'))->get();
    	echo json_encode($data);
    }

    public function replay(Request $request){
    	
    	// 设置自定义验证信息
        $message = [
            'required' => '回复不能为空',

        ];

        $this->validate($request,[
            'replayContent' => 'required',
            ],$message);

        //获取提事件
    	$replayTime = time();

    	//获取数据
    	$data = $request->except('_token');
    	$data['replayer'] = session('adminUser')['adminName'];
    	$data['replayTime'] = $replayTime;
        $replayCid = $data['replayCid'];
    	$row = DB::table('stroereplay')->insertGetId($data);

    	if ( $row > 0 ) {

            //修改回复状态
            $row = DB::table('storecomment')->where('commentId',$replayCid)->update(['commentStatu' => '1']);
          // dd($row);
    		return redirect('/admin/comment')->with('msg','回复成功');
    	}  

    	
    }

    public function delReplay($id)
    {

        $row = DB::table('stroereplay')->where('replayId',$id)->delete();

        if ( $row > 0 ) {
            return back()->with('msg','删除信息成功');
        } 

        return back()->with('msg','删除信息失败');
    }


}
